#include <stdio.h>
#include "log/log.h"
#include "cJSON/cJSON.h"

int main(int argc, char *argv[]){
    cJSON *root = cJSON_CreateObject();
    cJSON_AddStringToObject(root, "name", "zhangsan");
    cJSON_AddNumberToObject(root, "age", 18);
    cJSON_AddBoolToObject(root, "isStudent", true);
    cJSON_AddStringToObject(root, "address", "beijing");
    cJSON_AddNumberToObject(root, "score", 100);
    cJSON_AddBoolToObject(root, "isPass", true);

    char *json_str = cJSON_Print(root);
    // printf("%s\n", json_str);
    log_info("json_str: %s", json_str);
    //解析json
    cJSON *json = cJSON_Parse(json_str);
    if(json == NULL){
        log_error("json parse error");
    }else{
        log_info("json parse success");
    }
    cJSON *name = cJSON_GetObjectItem(json, "name");
    cJSON *age = cJSON_GetObjectItem(json, "age");
    log_info("name: %s,age: %d", name->valuestring,age->valueint);
    cJSON_Delete(json);
    cJSON_Delete(root);
    return 0;
}